#define _CRT_SECURE_NO_WARNINGS 1
#include"test.h"

Date::Date(int year, int month, int day)
{
	_year = year;
	_month = month;
	_day = day;
}

bool Date::operator<(const Date& x)
{
	if (_year < x._year)
	{
		return true;
	}
	else if (_year == x._year && _month <= x._month)
	{
		return true;
	}
	else if (_year == x._year && _month == x._month && _day < x._day)
	{
		return true;
	}

	else
	{
		return false;
	}
}

bool Date::operator==(const Date& x)
{
	return (_year == x._year && _month == x._month && _day == x._day);
}

bool Date::operator<=(const Date& x)
{
	return *this < x || *this == x;
}
bool Date::operator>(const Date& x)
{
	return !(*this <= x);
}
bool Date::operator>=(const Date& x)
{
	return !(*this < x);
}

bool Date::operator!=(const Date& x)
{
	return !(*this == x);
}


int Date::GetMonthDay(int year, int month)
{
	static int dayarr[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
	if ((month == 2) && ((month / 400 == 0) || ((month / 100 != 0) && (month % 4 == 0))))
	{
		return 29;
	}
	else
	{
		return dayarr[month];
	}
}

Date& Date::operator+=(int day)
{
	//*this=*this + day;
	//return *this;

	_day += day;
	while (_day > GetMonthDay(_year, _month))
	{
		_day -= GetMonthDay(_year, _month);
		_month++;
		if (_month > 12)
		{
			_month = 1;
			_year++;
		}
	}
	return *this;
}

Date& Date::operator+(int day)
{
	Date tmp(*this);
	tmp += day;
	//tmp._day += day;
	//while (tmp._day > GetMonthDay(tmp._year, tmp._month))
	//{
	//	tmp._day -= GetMonthDay(tmp._year, tmp._month);
	//	_month++;
	//	if (tmp._month > 12)
	//	{
	//		tmp._month = 1;
	//		tmp._year++;
	//	}
	//}
	return *this;
}